<?php
namespace app\controllers\api\account;

use fate\http\Request;
use app\models\User;
use app\models\UserCredit;
use app\libs\LibUser;

class GetuserController extends \fate\web\PureController {
    public function run() {
        $req = Request::getInstance();

        $uid = $req->getQueryString('uid');
        $uid = LibUser::decodeId($uid);

        if(!is_numeric($uid)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        $user = new User();
        $ret = $user->getOne('gender,user_name,avatar,short_intro', $uid);

        if(null === $ret) {
            $this->ajaxReturn(null, 100008);
            exit;
        }

        // 经验
        $ret['credit'] = (new UserCredit())->getUserLevel($uid);

        $this->ajaxReturn([
            'data' => $ret
        ]);
    }
}
